//
//  HTClassUIViewEx.swift
//  QuitSmokingApp
//
//  Created by   on 2024/3/12.
//

import Foundation
import UIKit

extension UIView {
    
    /// 创建一个纵向渐变色
    ///
    /// - Parameters:
    ///   - startColor: 渐变色的起始颜色
    ///   - endColor: 渐变色的结束颜色
    func ht_setVerticalGradient(startColor: UIColor, endColor: UIColor) {
        let gradientLayer = CAGradientLayer()
        gradientLayer.frame = self.bounds
        gradientLayer.colors = [startColor.cgColor, endColor.cgColor]
        gradientLayer.startPoint = CGPoint(x: 0.5, y: 0.0)
        gradientLayer.endPoint = CGPoint(x: 0.5, y: 1.0)
        self.layer.insertSublayer(gradientLayer, at: 0)
    }
    
    func ht_roundCorners(_ var_corners: UIRectCorner, var_radius: CGFloat) {
        let var_maskPath = UIBezierPath(roundedRect: bounds,
                                        byRoundingCorners: var_corners,
                                        cornerRadii: CGSize(width: var_radius, height: var_radius))
        
        let var_maskLayer = CAShapeLayer()
        var_maskLayer.path = var_maskPath.cgPath
        layer.mask = var_maskLayer
    }
}
